// use std::io::stdin;

fn main() {
    // let mut msg = String::new();
    // println!("Please enter message:");
    // stdin().read_line(&mut msg).unwrap();
    // println!("Message is {}", msg);
    // let a: u32 = 5;
    // let b: i32 = 10;
    // println!("{} + {} = {}", a, b, a + b as u32);

    // const CONS_NUM: u32 = 3244;
    // println!("{}", CONS_NUM);

    let current_temp = 10.0;
    let temp = convert_temp(current_temp, "C", "F");
    println!("{} C is {} F", current_temp, temp);

    let fibonacci_n = fibonacci(10);
    println!("Fibonacci number is {}", fibonacci_n);
}

fn convert_temp(temp: f64, from: &str, to: &str) -> f64 {
    match from {
        "C" => match to {
            "F" => temp * 9.0 / 5.0 + 32.0,
            "K" => temp + 273.15,
            _ => panic!("Invalid to unit"),
        },
        "F" => match to {
            "C" => (temp - 32.0) * 5.0 / 9.0,
            "K" => (temp - 32.0) * 5.0 / 9.0 + 273.15,
            _ => panic!("Invalid to unit"),
        },
        "K" => match to {
            "C" => temp - 273.15,
            "F" => (temp - 273.15) * 9.0 / 5.0 + 32.0,
            _ => panic!("Invalid to unit"),
        },
        _ => panic!("Invalid from unit"),
    }
}

// 生成第 n 个斐波那契数
fn fibonacci(n: i32) -> i32 {
    match n {
        0 | 1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

fn fibonacci_1(n: i32) -> i32 {
    if n <= 1 {
        1
    } else {
        fibonacci(n - 1) + fibonacci(n - 2)
    }
}
// crate
// -- library crate 只能有一个
// -- binary crate 可以有多个